using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleNet
{
    /// <summary>
    /// Icon used in the List view that reflects the state of a Folder or Link fetch. 
    /// Icons associated with the open and closed modes are used for Folders. 
    /// Icons associated with the error and fetching0, fetching1, and fetching2 modes are used for Network Links. 
    /// </summary>
    public class KmlItemIcon: IKmlElement
    {
        private string tagName = "ItemIcon";

        #region State
        private KmlItemIconModes state = KmlItemIconModes.closed;

        /// <summary>
        /// specifies the current state of the NetworkLink or Folder. 
        /// Possible values are open, closed, error, fetching0, fetching1, and fetching2. 
        /// <remarks>These values can be combined by inserting a space between two values (no comma).</remarks> 
        /// </summary>
        /// <value>The state.</value>
        public KmlItemIconModes State
        {
            get { return state; }
            set { state = value; }
        } 
        #endregion

        #region Href
        private Uri href;

        /// <summary>
        /// specifies the URI of the image used in the List View for the Feature. 
        /// <remarks>
        /// A URL (either an HTTP address or a local file specification). 
        /// <list type="bullet">
        /// <item>When the parent of Link is a NetworkLink, href is a KML file.</item>
        /// <item>When the parent of Link is a Model, href is a COLLADA file. </item>
        /// <item>When the parent of Link is an Overlay, href is an image. </item>
        /// </list>
        /// Relative URLs can be used in this tag and are evaluated relative to the enclosing KML file. 
        /// </remarks>
        /// </summary>
        /// <value>The href.</value>
        public Uri Href
        {
            get { return href; }
            set { href = value; }
        }
        #endregion

        #region IKmlElement Members

        /// <summary>
        /// Name of the KML tag for this specific element.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        public string TagName
        {
            get { return tagName; }
        }

        #endregion

        #region IKmlGenerator Members

        /// <summary>
        /// Generates the KML for this element including its child elements.
        /// </summary>
        /// <param name="writer">The XML writer that will be used to generate the KML.</param>
        public void GenerateKml(System.Xml.XmlTextWriter writer)
        {
            writer.WriteStartElement(tagName);

            writer.WriteElementString("state", state.ToString());
            if(href != null)
            writer.WriteElementString("href", href.ToString());

            writer.WriteEndElement();
        }

        #endregion
    }
}
